import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.logging.Logger;
import java.util.regex.*;

import javax.imageio.ImageIO;
import javax.swing.*;

import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.util.GlobalConfiguration;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Skills;

@ScriptManifest(authors = { "Fletch To 99" }, keywords = "Fletching", name = "UFletch", version = 2.0, description = "The best fletcher!")
/**
 * All-in-One Fletching script for RSBot 2.XX
 * @author Fletch To 99
 */
public class UFletch extends Script implements PaintListener, MouseListener,
		MouseMotionListener, MessageListener {

	int amount;
	int startLevel;
	int startXP;
	int fletched;
	int strung;
	long startTime = System.currentTimeMillis();
	int xpIsClose = 13020000;
	long hoverTime = 0;
	int currentexp;
	public int Mouse1 = 50;
	public int Mouse2 = 8;
	int xpGained = 0;
	int xpToLevel = 0;
	int hoursTNL = 0;
	int secsTNL = 0;
	int minsTNL = 0;

	Point p;
	Point p2;
	Point z;

	Image paint;
	Image hide;
	Image show;
	Image guiButton;
	Image watermark;

	double version = 0.0;
	double newver = 0.0;

	Font titleFont = new Font("Allerta", Font.PLAIN, 22);
	Font textFont = new Font("Allerta", Font.PLAIN, 11);

	boolean fullPaint = true;
	boolean isClicking = false;
	boolean fletchAndString = false;

	private static final String UPDATER_FILE_NAME = "UFletch.java";
	private static final String UPDATER_URL = "http://www.universalscripts.org/UFletch.java";
	private static final Pattern UPDATER_VERSION_PATTERN = Pattern
			.compile("version\\s*=\\s*([0-9.]+)");

	Color BLACK = new Color(0, 0, 0, 255);
	Color WHITE = new Color(255, 250, 250);
	Color GREEN = new Color(0, 90, 0, 225);
	Color RED = new Color(90, 0, 0, 225);
	Color GREENISH = new Color(0, 193, 0);
	Color GREENISH2 = new Color(0, 193, 0, 45);
	Color TAN = new Color(220, 202, 169);
	Color TAN2 = new Color(220, 202, 169, 125);

	String status = "";

	public gui gui;

	private final LinkedList<MousePathPoint> mousePath = new LinkedList<MousePathPoint>();
	private final LinkedList<MousePathPoint2> mousePath2 = new LinkedList<MousePathPoint2>();

	String[] optionMethod = { "Fletch", "String", "Fletch&String", "Shafts",
			"Stocks" };
	String[] optionLog = { "Normal", "Oak", "Willow", "Maple", "Yew", "Magic" };
	String[] optionBow = { "Short", "Long", "N/A" };
	String[] optionKnife = { "Normal", "clay", "N/A" };

	public int getMethod() {
		if (gui.comboBox1.getSelectedIndex() == 0) {
			return 1;
		} else if (gui.comboBox1.getSelectedIndex() == 1) {
			return 2;
		} else if (gui.comboBox1.getSelectedIndex() == 2) {
			return 3;
		} else if (gui.comboBox1.getSelectedIndex() == 3) {
			return 4;
		} else if (gui.comboBox1.getSelectedIndex() == 4) {
			return 5;
		}
		return -1;
	}

	public int getLogId() {
		if (gui.comboBox2.getSelectedIndex() == 0) {
			return 1511;
		} else if (gui.comboBox2.getSelectedIndex() == 1) {
			return 1521;
		} else if (gui.comboBox2.getSelectedIndex() == 2) {
			return 1519;
		} else if (gui.comboBox2.getSelectedIndex() == 3) {
			return 1517;
		} else if (gui.comboBox2.getSelectedIndex() == 4) {
			return 1515;
		} else if (gui.comboBox2.getSelectedIndex() == 5) {
			return 1513;
		}
		return -1;
	}

	public int getUnstrungId() {
		if (getBowType() == 1) { // 1 = Shortbows, 2 = Longbows
			if (gui.comboBox2.getSelectedIndex() == 0) {
				return 50;
			} else if (gui.comboBox2.getSelectedIndex() == 1) {
				return 54;
			} else if (gui.comboBox2.getSelectedIndex() == 2) {
				return 60;
			} else if (gui.comboBox2.getSelectedIndex() == 3) {
				return 64;
			} else if (gui.comboBox2.getSelectedIndex() == 4) {
				return 68;
			} else if (gui.comboBox2.getSelectedIndex() == 5) {
				return 72;
			}
		} else {
			if (gui.comboBox2.getSelectedIndex() == 0) {
				return 48;
			} else if (gui.comboBox2.getSelectedIndex() == 1) {
				return 56;
			} else if (gui.comboBox2.getSelectedIndex() == 2) {
				return 58;
			} else if (gui.comboBox2.getSelectedIndex() == 3) {
				return 62;
			} else if (gui.comboBox2.getSelectedIndex() == 4) {
				return 66;
			} else if (gui.comboBox2.getSelectedIndex() == 5) {
				return 70;
			}
		}
		return -1;
	}

	public int getStrungId() {
		if (getBowType() == 1) { // 1 = Shortbows, 2 = Longbows
			if (gui.comboBox2.getSelectedIndex() == 0) {
				return 481;
			} else if (gui.comboBox2.getSelectedIndex() == 1) {
				return 843;
			} else if (gui.comboBox2.getSelectedIndex() == 2) {
				return 849;
			} else if (gui.comboBox2.getSelectedIndex() == 3) {
				return 853;
			} else if (gui.comboBox2.getSelectedIndex() == 4) {
				return 857;
			} else if (gui.comboBox2.getSelectedIndex() == 5) {
				return 861;
			}
		} else {
			if (gui.comboBox2.getSelectedIndex() == 0) {
				return 839;
			} else if (gui.comboBox2.getSelectedIndex() == 1) {
				return 845;
			} else if (gui.comboBox2.getSelectedIndex() == 2) {
				return 847;
			} else if (gui.comboBox2.getSelectedIndex() == 3) {
				return 851;
			} else if (gui.comboBox2.getSelectedIndex() == 4) {
				return 855;
			} else if (gui.comboBox2.getSelectedIndex() == 5) {
				return 859;
			}
		}
		return -1;
	}

	public int getBowType() {
		if (gui.comboBox3.getSelectedIndex() == 0) {
			return 1;
		} else if (gui.comboBox3.getSelectedIndex() == 1) {
			return 2;
		}
		return -1;
	}

	public int getKnifeId() {
		if (gui.comboBox4.getSelectedIndex() == 0) {
			return 946;
		} else if (gui.comboBox4.getSelectedIndex() == 1) {
			return 14111;
		}
		return -1;
	}

	public boolean isBusy() {
		if (getMethod() == 2) {
			if (getMyPlayer().getAnimation() == -1) {
				for (int i = 0; i < 50; i++) {
					sleep(50);
					if (getMyPlayer().getAnimation() != -1
							|| inventory.getCount() == 28
							|| inventory.getCount() == 0) {
						break;
					}
				}
			}
		}
		sleep(25);
		return (getMyPlayer().getAnimation() != -1);
	}

	public boolean openBank() {
		try {
			return bank.open();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}

	public int loop() {
		if (getMethod() == 1) {
			fletch();
			sleep(random(200, 250));
		} else if (getMethod() == 2) {
			string();
			sleep(random(200, 250));
		} else if (getMethod() == 3) {
			fletchAndString();
			sleep(random(200, 250));
		} else if (getMethod() == 4) {
			shafts();
			sleep(random(200, 250));
		} else if (getMethod() == 5) {
			stocks();
			sleep(random(200, 250));
		}
		return random(200, 300);
	}

	public void fletch() {
		amount = Integer.parseInt(gui.textField1.getText());
		if (!inventory.contains(getKnifeId()) && amount == 0 && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawKnife();
			sleep(random(200, 250));
		}
		if (!inventory.contains(getKnifeId()) && fletched <= amount
				&& !isBusy() && !interfaces.get(905).isValid()) {
			withdrawKnife();
			sleep(random(200, 250));
		}
		if (!inventory.contains(getLogId()) && amount == 0 && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawLogs();
			sleep(random(200, 250));
		} else if (!inventory.contains(getLogId()) && fletched <= amount
				&& !isBusy() && !interfaces.get(905).isValid()) {
			withdrawLogs();
			sleep(random(200, 250));
		} else if (fletchAndString && !isBusy() && fletched >= amount
				&& amount > 0) {
			gui.comboBox1.setSelectedItem("String");
			log("here1");
		} else if (fletchAndString && !isBusy() && amount == 0
				&& bank.getItem(getLogId()) == null
				&& !interfaces.get(905).isValid()) {
			sleep(random(50, 100));
			if (fletchAndString && !isBusy() && amount == 0
					&& bank.getItem(getLogId()) == null
					&& !interfaces.get(905).isValid()
					&& inventory.getCount() < 1) {
				gui.comboBox1.setSelectedItem("String");
				log("here 9");
			}
		} else if (fletched >= amount && amount != 0 && !fletchAndString) {
			log("Fletched amount logging out!");
			stopScript();
		}
		if (inventory.contains(getLogId())
				&& inventory.containsOneOf(getKnifeId()) && amount == 0
				&& !isBusy()) {
			fletchLogs();
			sleep(random(200, 250));
		} else if (inventory.contains(getLogId())
				&& inventory.containsOneOf(getKnifeId()) && fletched <= amount
				&& !isBusy()) {
			fletchLogs();
			sleep(random(100, 250));
		} else if (fletchAndString && !isBusy() && fletched >= amount
				&& amount > 0) {
			gui.comboBox1.setSelectedItem("String");
			log("here2");
		} else if (fletchAndString && !isBusy() && amount == 0
				&& bank.getItem(getLogId()) == null
				&& !interfaces.get(905).isValid()) {
			sleep(random(50, 100));
			if (fletchAndString && !isBusy() && amount == 0
					&& bank.getItem(getLogId()) == null
					&& !interfaces.get(905).isValid()
					&& inventory.getCount() < 1) {
				gui.comboBox1.setSelectedItem("String");
				log("here 9");
			}
		} else if (fletched >= amount && amount != 0 && !isBusy()
				&& !fletchAndString) {
			log("Fletched amount logging out!");
			stopScript();
		}
		if (isBusy() && !interfaces.get(740).isValid()) {
			antiban();
			sleep(random(200, 250));
		}
		clickContinue();
		if (gui.checkBox5.isSelected()) {
			checkfor99();
		}
	}

	public void string() {
		amount = Integer.parseInt(gui.textField1.getText());
		if (!inventory.contains(getUnstrungId()) || !inventory.contains(1777)
				&& amount == 0 && !isBusy() && !interfaces.get(905).isValid()) {
			withdrawStrings();
			sleep(random(200, 250));
		} else if (!inventory.contains(getUnstrungId())
				|| !inventory.contains(1777) && strung <= amount && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawStrings();
			sleep(random(200, 250));
		} else if (strung >= amount && amount != 0) {
			log("strung the chosen amount of bows!");
			stopScript();
		}
		if (inventory.contains(getUnstrungId()) && inventory.contains(1777)
				&& amount == 0 && !isBusy()) {
			stringBows();
			sleep(random(200, 250));
		} else if (inventory.contains(getUnstrungId())
				&& inventory.contains(1777) && strung <= amount && !isBusy()) {
			stringBows();
			sleep(random(200, 250));
		} else if (strung >= amount && amount != 0) {
			log("strung the chosen amount of bows!");
			stopScript();
		}

		if (isBusy() && !interfaces.get(740).isValid()
				&& inventory.contains(1777)
				&& inventory.contains(getUnstrungId())) {
			antiban();
			sleep(random(400, 500));
		}
		clickContinue();
		if (gui.checkBox5.isSelected()) {
			checkfor99();
		}
	}

	public void fletchAndString() {
		fletchAndString = true;
		gui.comboBox1.setSelectedItem("Fletch");
	}

	public void shafts() {
		amount = Integer.parseInt(gui.textField1.getText());
		if (!inventory.contains(getKnifeId()) && amount == 0 && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawKnife();
			sleep(random(200, 250));
		} else if (!inventory.contains(getKnifeId()) && fletched <= amount
				&& !isBusy() && !interfaces.get(905).isValid()) {
			withdrawKnife();
			sleep(random(200, 250));
		} else if (fletched >= amount && amount != 0) {
			log("Done the amount required!");
			stopScript();
		}
		if (!inventory.contains(getLogId()) && amount == 0 && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawShafts();
			sleep(random(200, 400));
		} else if (!inventory.contains(getLogId()) && fletched <= amount
				&& !isBusy() && !interfaces.get(905).isValid()) {
			withdrawShafts();
			sleep(random(200, 400));
		} else if (fletched >= amount && amount != 0) {
			log("Done the amount required!");
			stopScript();
		}
		if (inventory.contains(getLogId())
				&& inventory.containsOneOf(getKnifeId()) && amount == 0
				&& !isBusy()) {
			fletchShafts();
			sleep(random(200, 250));
		} else if (inventory.contains(getLogId()) && fletched <= amount
				&& !isBusy()) {
			fletchShafts();
			sleep(random(200, 250));
		} else if (fletched >= amount && amount != 0) {
			log("Done the amount required!");
			stopScript();
		}
		while (isBusy() && !interfaces.get(740).isValid()) {
			antiban();
			sleep(random(200, 250));
		}
		clickContinue();
		if (gui.checkBox5.isSelected()) {
			checkfor99();
		}
	}

	public void stocks() {
		amount = Integer.parseInt(gui.textField1.getText());
		if (!inventory.contains(getKnifeId()) && amount == 0 && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawKnife();
			sleep(random(200, 250));
		} else if (!inventory.contains(getKnifeId()) && fletched <= amount
				&& !isBusy() && !interfaces.get(905).isValid()) {
			withdrawKnife();
			sleep(random(200, 250));
		} else if (fletched >= amount && amount != 0) {
			log("Done the amount required!");
			stopScript();
		}
		if (!inventory.contains(getLogId()) && amount == 0 && !isBusy()
				&& !interfaces.get(905).isValid()) {
			withdrawStocks();
		} else if (!inventory.contains(getLogId()) && fletched <= amount
				&& !isBusy() && !interfaces.get(905).isValid()) {
			withdrawStocks();
		} else if (fletched >= amount && amount != 0) {
			log("Done the amount required!");
			stopScript();
		}
		if (inventory.contains(getLogId())
				&& inventory.containsOneOf(getKnifeId()) && amount == 0
				&& !isBusy()) {
			fletchStocks();
			sleep(random(200, 250));
		} else if (inventory.contains(getLogId()) && fletched <= amount
				&& !isBusy()) {
			fletchStocks();
			sleep(random(200, 250));
		} else if (fletched >= amount && amount != 0) {
			log("Done the amount required!");
			stopScript();
		}
		while (isBusy() && !interfaces.get(740).isValid()) {
			antiban();
			sleep(random(200, 250));
		}
		clickContinue();
		if (gui.checkBox5.isSelected()) {
			checkfor99();
		}
	}

	public void clickContinue() {
		if (interfaces.get(740).isValid()) {
			status = "Level up: Clicking Continue";
			sleep(50, 75);
			if (gui.checkBox2.isSelected()) {
				env.saveScreenshot(true);
			}
			sleep(150, 1500);
			interfaces.get(740).getComponent(3).doClick(true);
			sleep(150, 400);
		}
	}

	public void checkfor99() {
		currentexp = skills.getCurrentExp(Skills.FLETCHING);
		if (currentexp >= xpIsClose) {
			status = "Check 99: Logging out";
			if (bank.isOpen()) {
				bank.close();
			}
			stopScript(true);
		}
	}

	public void withdrawKnife() {
		status = "Banking: Knife";
		try {
			sleep(10, 20);
			openBank();
			sleep(200, 400);
			if (bank.isOpen()) {
				sleep(100, 250);
				if (!inventory.contains(getKnifeId())) {
					if (inventory.getCount() > 0)
						bank.depositAll();
					sleep(100, 150);
					if (getMethod() != 3) {
						if (bank.getItem(getKnifeId()) == null) {
							log("could not find a knife, logging out!");
							stopScript();
						}
					}
					bank.withdraw(getKnifeId(), 1);
					sleep(50, 100);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void withdrawLogs() {
		status = "Banking: Logs";
		try {
			sleep(10, 20);
			if (openBank()) {
				if (bank.isOpen()) {
					sleep(200, 400);
					if (bank.depositAllExcept(getKnifeId())) {
						for (int i = 0; i < 10; i++) {
							sleep(30);
							if (inventory.getCount() == 0) {
								break;
							}
						}
					}
					if (bank.getItem(getLogId()) == null) {
						if (fletchAndString) {
							gui.comboBox1.setSelectedItem("String");
						} else {
							log("could not find any Logs, logging out!");
							stopScript();
						}
					}
					bank.withdraw(getLogId(), 0);
					sleep(50, 100);
					for (int i = 0; i < 25; i++) {
						sleep(50);
						if (inventory.contains(getLogId())) {
							break;
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void withdrawStrings() {
		status = "Banking: Stringing";
		try {
			if (!inventory.contains(1777)
					|| !inventory.contains(getUnstrungId())) {
				openBank();
				if (bank.isOpen()) {
					if (inventory.getCount() > 0) {
						bank.depositAll();
						sleep(50);
						for (int i = 0; i < 20; i++) {
							sleep(25);
							if (inventory.getCount() == 0) {
								break;
							}
						}
					}
					if (!inventory.contains(getUnstrungId())) {
						if (bank.getCount(getUnstrungId()) > 0) {
							bank.withdraw(getUnstrungId(), 14);
							sleep(100);
							for (int i = 0; i < 50; i++) {
								sleep(25);
								if (inventory.contains(getUnstrungId())) {
									break;
								}
							}
						} else {
							log("No more bows (u) in bank.");
							stopScript(true);
						}
					}
					if (!inventory.contains(getUnstrungId())) {
						withdrawStrings();
					}
					if (!inventory.contains(1777)) {
						if (bank.getCount(1777) > 0) {
							bank.withdraw(1777, 0);
							sleep(100);
							for (int i = 0; i < 50; i++) {
								sleep(25);
								if (inventory.contains(1777)) {
									break;
								}
							}
						} else {
							log("No more bowstring in bank.");
							stopScript(true);
						}
					}
					if (inventory.getCount(1777) > 14
							|| inventory.getCount(getUnstrungId()) > 14) {
						withdrawStrings();
					}
					if (inventory.getCount(1777) < 14
							|| inventory.getCount(getUnstrungId()) < 14) {
						withdrawStrings();
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void withdrawShafts() {
		status = "Banking: Shafts";
		try {
			sleep(10, 20);
			if (openBank()) {
				if (getLogId() != 1511) {
					log("Please select normal logs!");
					stopScript();
				} else if (getLogId() == 1511 && bank.isOpen()) {
					sleep(200, 400);
					bank.depositAllExcept(getKnifeId());
					sleep(100, 150);
					if (bank.getItem(getLogId()) == null) {
						log("Out of logs, Logging out!");
						stopScript();
					}
					bank.withdraw(getLogId(), 0);
					for (int i = 0; i < 200; i++) {
						sleep(50);
						if (inventory.contains(getLogId())) {
							bank.close();
							break;
						}
					}
					sleep(30, 50);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void withdrawStocks() {
		status = "Banking: Stocks";
		try {
			sleep(10, 20);
			if (openBank()) {
				if (getLogId() == 1513) {
					log("Please select a different log!");
					stopScript();
				} else if (getLogId() != 1513 && bank.isOpen()) {
					sleep(200, 400);
					bank.depositAllExcept(getKnifeId());
					sleep(100, 150);
					if (bank.getItem(getLogId()) == null) {
						log("Out of logs, Logging out!");
						stopScript();
					}
					bank.withdraw(getLogId(), 0);
					for (int i = 0; i < 200; i++) {
						sleep(50);
						if (inventory.contains(getLogId())) {
							bank.close();
							break;
						}
					}
					sleep(30, 50);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void fletchLogs() {
		status = "Fletching: UBows";
		try {
			if (bank.isOpen()) {
				bank.close();
			}
			sleep(50, 100);
			if (!interfaces.get(905).isValid() && !isBusy()
					&& inventory.containsOneOf(getKnifeId())) {
				if (random(1, 2) == 1) {
					inventory.getItem(getLogId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(getKnifeId()).doClick(true);
				} else {
					inventory.getItem(getKnifeId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(getLogId()).doClick(true);
				}
			}
			sleep(50, 100);
			mouse.move(random(35, 448), random(500, 355));
			sleep(400, 450);
			if (interfaces.get(905).isValid()) {
				if (getBowType() == 1) {
					status = "Fletching: short";
					if (getLogId() == 1511) {
						sleep(200, 250);
						interfaces.get(905).getComponent(15)
								.doAction("Make All");
					} else {
						sleep(200, 250);
						interfaces.get(905).getComponent(14)
								.doAction("Make All");
					}
				}
				if (getBowType() == 2) {
					status = "Fletching: long";
					if (getLogId() == 1511) {
						sleep(200, 250);
						interfaces.get(905).getComponent(16)
								.doAction("Make All");
					} else {
						sleep(200, 250);
						interfaces.get(905).getComponent(15)
								.doAction("Make All");
					}
				}
			}
			sleep(50, 200);
		} catch (Exception e) {
		}
	}

	public void stringBows() {
		status = "Stringing: Bows";
		try {
			if (bank.isOpen()) {
				bank.close();
			}
			if (!interfaces.get(905).isValid() && !isBusy()
					&& inventory.contains(1777)
					&& inventory.contains(getUnstrungId())) {
				if (random(1, 2) == 1) {
					inventory.getItem(getUnstrungId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(1777).doClick(true);
					sleep(random(200, 400));
				} else {
					inventory.getItem(1777).doClick(true);
					sleep(200, 400);
					inventory.getItem(getUnstrungId()).doClick(true);
					sleep(random(200, 400));
				}
			}
			sleep(50, 100);
			mouse.moveRandomly(150, 500);
			sleep(400, 450);
			if (interfaces.get(905).isValid()) {
				sleep(200, 250);
				interfaces.get(905).getComponent(14).doAction("Make All");
				sleep(50, 200);
			}
		} catch (Exception e) {
		}
	}

	public void fletchShafts() {
		status = "Fletching: Shafts";
		try {
			if (bank.isOpen())
				bank.close();
			sleep(50, 100);
			if (!interfaces.get(905).isValid() && !isBusy()) {
				if (random(1, 2) == 1) {
					inventory.getItem(getLogId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(getKnifeId()).doClick(true);
				} else {
					inventory.getItem(getKnifeId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(getLogId()).doClick(true);
				}
			}
			sleep(50, 100);
			mouse.moveRandomly(150, 500);
			sleep(400, 450);
			if (interfaces.get(905).isValid()) {
				if (getLogId() == 1511) {
					sleep(200, 250);
					interfaces.get(905).getComponent(14).doClick(true);
				} else if (getLogId() != 1511) {
					log("Please select normal logs!");
					stopScript();
				}
			}
			sleep(50, 200);
		} catch (Exception e) {
		}
	}

	public void fletchStocks() {
		status = "Fletching: Stocks";
		try {
			if (bank.isOpen())
				bank.close();
			sleep(50, 100);
			if (!interfaces.get(905).isValid() && !isBusy()) {
				if (random(1, 2) == 1) {
					inventory.getItem(getLogId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(getKnifeId()).doClick(true);
				} else {
					inventory.getItem(getKnifeId()).doClick(true);
					sleep(200, 400);
					inventory.getItem(getLogId()).doClick(true);
				}
			}
			sleep(50, 100);
			mouse.moveRandomly(150, 500);
			sleep(400, 450);
			if (interfaces.get(905).isValid()) {
				if (getLogId() == 1513) {
					log("Please slect a different log!");
					stopScript();
				} else if (getLogId() != 1513) {
					if (getLogId() == 1511) {
						sleep(200, 250);
						interfaces.get(905).getComponent(17).doClick(true);
					} else {
						sleep(200, 250);
						interfaces.get(905).getComponent(17).doClick(true);
					}
				}
			}
			sleep(50, 200);
		} catch (Exception e) {
		}
	}

	@Override
	public void messageReceived(MessageEvent e) {
		try {
			String m = e.getMessage().toLowerCase();
			if (m.contains("you carefully cut")) {
				fletched++;
			}
			if (m.contains("you add a string to the bow")) {
				strung++;
			}
		} catch (Exception e1) {
		}
	}

	private void antiban() {
		status = "Antiban:";
		int r = random(1, 200);
		if (r == 1) {
			status = "Antiban: Mouse";
			mouse.moveRandomly(100, 200);
			sleep(random(2000, 2500));
		}
		if (r == 6) {
			status = "Antiban: Mouse";
			mouse.moveRandomly(25, 150);
			sleep(random(1000, 2500));
		}
		if (r == 12) {
			status = "Antiban: Stats";
			if (game.getCurrentTab() != 1) {
				game.openTab(1);
				sleep(350, 500);
				mouse.move(random(615, 665), random(350, 375));
				sleep(1000, 1200);
				if (game.getCurrentTab() != 4) {
					game.openTab(4);
					sleep(random(100, 200));
				}
			}
		}
		if (r == 19) {
			status = "Antiban: AFK";
			sleep(random(2000, 2500));
		}
		if (r == 26) {
			status = "Antiban: Camera";

			camera.setAngle(random(0, 300));
			camera.setPitch(random(35, 85));
			sleep(random(1750, 1950));
		}
	}

	private boolean checkForUpdates() {
		try {
			double currentVer = UFletch.class.getAnnotation(
					ScriptManifest.class).version();
			double newVer = -1;
			URL url = new URL(UPDATER_URL);
			BufferedReader in = new BufferedReader(new InputStreamReader(
					url.openStream()));
			String line, lines = "";
			Matcher m;
			while ((line = in.readLine()) != null) {
				lines += line + "\n";
				if ((m = UPDATER_VERSION_PATTERN.matcher(line)).find()) {
					newVer = Double.parseDouble(m.group(1));
					break;
				}
			}
			if (newVer < 0) {
				in.close();
				log("Unable to find the new version number. Update failed");
				return false;
			}
			if (currentVer >= newVer) {
				in.close();
				log("You already have the latest version of the script.");
				return false;
			}
			log("Update found! Downloading version " + newVer);
			String scriptFilePath = GlobalConfiguration.Paths
					.getScriptsSourcesDirectory() + "\\" + UPDATER_FILE_NAME;
			PrintWriter out = new PrintWriter(scriptFilePath);
			out.print(lines);
			while ((line = in.readLine()) != null)
				out.println(line);
			out.close();
			in.close();
			log("Successfully saved " + UPDATER_FILE_NAME + " to "
					+ GlobalConfiguration.Paths.getScriptsSourcesDirectory());
			log("Compiling...");
			try {
				Runtime.getRuntime().exec(
						new String[] { "javac", "-classpath", "RSBot.jar",
								scriptFilePath });
			} catch (Exception ex) {
				log("Could not compile the script. Please manually compile to finish the update.");
				return false;
			}
			log("Update successful!");
			log("The new version will appear near the bottom of the script selector.");
			log("Stopping the script. restart to run the newer version.");
			stopScript();
			return true;
		} catch (IOException e) {
			log(e.toString());
			log("Update failed.");
		}
		return false;
	}

	String urversion() {
		return Double.toString(version);
	}

	String newversion() {
		return Double.toString(newver);
	}

	public boolean onStart() {
		try {
			version = UFletch.class.getAnnotation(ScriptManifest.class)
					.version();
			URL url = new URL(UPDATER_URL);
			BufferedReader in = new BufferedReader(new InputStreamReader(
					url.openStream()));
			String line, lines = "";
			Matcher m;
			while ((line = in.readLine()) != null) {
				lines += line + "\n";
				if ((m = UPDATER_VERSION_PATTERN.matcher(line)).find()) {
					newver = Double.parseDouble(m.group(1));
					break;
				}
			}
		} catch (Exception e) {

		}
		gui = new gui();
		loadSettings();
		if (gui.textField2.getText().equals("all")) {
			gui.textField2.setEnabled(true);
			gui.button4.setEnabled(true);
		} else {
			gui.textField2.setEnabled(false);
			gui.button4.setEnabled(false);
		}
		gui.setVisible(true);
		while (gui.isVisible()) {
			sleep(random(200, 400));
		}
		try {
			paint = Images.getImage("ufletchpaint.png");
			hide = Images.getImage("hidepaint.png");
			show = Images.getImage("showpaint.png");
			guiButton = Images.getImage("button.png");
			watermark = Images.getImage("watermark.png");
			while (!game.isLoggedIn()) {
				sleep(random(100, 200));
			}
			sleep(random(400, 500));
			startLevel = skills.getRealLevel(Skills.FLETCHING);
			startXP = skills.getCurrentExp(Skills.FLETCHING);
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	public void updateSignature() {
		try {
			long xpGained = skills.getCurrentExp(Skills.FLETCHING) - startXP;
			long millis = System.currentTimeMillis() - startTime;
			long hours = millis / (1000 * 60 * 60);
			millis -= hours * (1000 * 60 * 60);
			long minutes = millis / (1000 * 60);
			millis -= minutes * (1000 * 60);
			long seconds = millis / 1000;
			URL url;
			URLConnection urlConn;
			url = new URL("http://www.universalscripts.org/UFletch_submit.php");
			urlConn = url.openConnection();
			urlConn.setRequestProperty("User-Agent", "hax");
			urlConn.setDoInput(true);
			urlConn.setDoOutput(true);
			urlConn.setUseCaches(false);
			urlConn.setRequestProperty("Content-Type",
					"application/x-www-form-urlencoded");
			String content = "";
			String[] stats = { "auth", "secs", "mins", "hours", "fletched",
					"strung", "expgained" };
			Object[] data = { gui.textField2.getText(), seconds, minutes,
					hours, fletched, strung, xpGained };
			for (int i = 0; i < stats.length; i++) {
				content += stats[i] + "=" + data[i] + "&";
			}
			content = content.substring(0, content.length() - 1);
			OutputStreamWriter wr = new OutputStreamWriter(
					urlConn.getOutputStream());
			wr.write(content);
			wr.flush();
			BufferedReader rd = new BufferedReader(new InputStreamReader(
					urlConn.getInputStream()));
			String line;
			while ((line = rd.readLine()) != null) {
				if (line.contains("success")) {
					log(line);
				}
			}
			wr.close();
			rd.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void onFinish() {
		updateSignature();
		log.info("Thanks for using UFletch. Have a good one ;)");
		if (gui.checkBox1.isSelected()) {
			env.saveScreenshot(true);
		}
	}

	private static class Images {
		private static Logger log = Logger.getLogger(Images.class.getName());

		public static Image getImage(String fileName) {
			try {
				File f = new File(
						GlobalConfiguration.Paths.getScriptsDirectory() + "/"
								+ fileName);
				if (f.exists()) {
					log.info("Successfully loaded " + fileName
							+ " from scripts folder.");
					return ImageIO.read(f.toURI().toURL());
				}
				BufferedImage img = ImageIO.read(new URL(
						"http://universalscripts.org/UFletch/" + fileName));
				if (img != null) {
					log.info("Downlaoding images...");
					ImageIO.write((RenderedImage) img, "PNG", f);
					log.info("Saved " + fileName
							+ " to Scripts folder successfully.");
					return img;
				}
			} catch (IOException e) {
				log.info("No Internet Connection or Broken Image Link, Check for Script Update.");
			}
			return null;
		}
	}

	@SuppressWarnings("serial")
	private class MousePathPoint extends Point { // credits to Enfilade
		private int toColor(double d) {
			return Math.min(255, Math.max(0, (int) d));
		}

		private long finishTime;
		private double lastingTime;

		public MousePathPoint(int x, int y, int lastingTime) {
			super(x, y);
			this.lastingTime = lastingTime;
			finishTime = System.currentTimeMillis() + lastingTime;
		}

		public boolean isUp() {
			return System.currentTimeMillis() > finishTime;
		}

		public Color getColor() {
			return new Color(
					0,
					255,
					0,
					toColor(256 * ((finishTime - System.currentTimeMillis()) / lastingTime)));
		}
	}

	private class MousePathPoint2 extends Point { // credits to Enfilade
		/**
		 * 
		 */
		private static final long serialVersionUID = 3567008140194371837L;

		private int toColor(double d) {
			return Math.min(255, Math.max(0, (int) d));
		}

		private long finishTime;
		private double lastingTime;

		public MousePathPoint2(int x, int y, int lastingTime) {
			super(z.x, z.y);
			this.lastingTime = lastingTime;
			finishTime = System.currentTimeMillis() + lastingTime;
		}

		public boolean isUp2() {
			return System.currentTimeMillis() > finishTime;
		}

		public Color getColor2() {
			return new Color(
					255,
					0,
					0,
					toColor(256 * ((finishTime - System.currentTimeMillis()) / lastingTime)));
		}
	}

	private final RenderingHints rh = new RenderingHints(
			RenderingHints.KEY_TEXT_ANTIALIASING,
			RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

	public void onRepaint(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setRenderingHints(rh);
		long millis = System.currentTimeMillis() - startTime;
		long hours = millis / (1000 * 60 * 60);
		millis -= hours * (1000 * 60 * 60);
		long minutes = millis / (1000 * 60);
		millis -= minutes * (1000 * 60);
		long seconds = millis / 1000;
		xpGained = skills.getCurrentExp(Skills.FLETCHING) - startXP;
		xpToLevel = skills.getExpToNextLevel(Skills.FLETCHING);
		float xpsec = ((float) xpGained)
				/ (float) (seconds + (minutes * 60) + (hours * 60 * 60));
		float xpmin = xpsec * 60;
		float xphour = xpmin * 60;
		hoursTNL = (int) Math.floor(xpToLevel / xphour);
		minsTNL = (int) Math.floor(((xpToLevel / xphour) - hoursTNL) * 60);
		secsTNL = (int) Math
				.floor(((((xpToLevel / xphour) - hoursTNL) * 60) - minsTNL) * 60);

		// =========> Show All <=========

		if (fullPaint && !isClicking && game.isLoggedIn()) {
			g2.setColor(TAN);
			g2.fillRect(6, 344, 507, 129);
			g2.drawImage(paint, 6, 344, null);
			g2.drawImage(hide, 9, 347, null);
			g2.drawImage(guiButton, 360, 440, null);
			g2.drawImage(watermark, 305, 315, null);
			g2.setFont(new Font("Arial", 1, 15));
			g2.setColor(GREENISH);
			g2.drawString("Time Running: " + getRuntime(), 60, 372);
			g2.drawString(
					"Exp Gained: "
							+ (skills.getCurrentExp(Skills.FLETCHING) - startXP),
					60, 391);
			g2.drawString(
					"Exp/H: "
							+ getHourly(skills.getCurrentExp(Skills.FLETCHING)
									- startXP), 60, 409);
			if (getMethod() != 2) {
				g2.drawString("Fletched/Strung:  " + fletched, 60, 426);
				g2.drawString(
						"Fletched/Hr:  "
								+ ((int) (new Double(fletched)
										/ new Double(System.currentTimeMillis()
												- startTime) * new Double(
										60 * 60 * 1000))), 60, 444);
			} else if (getMethod() == 2) {
				g2.drawString("Fletched/Strung:  " + strung, 60, 426);
				g2.drawString(
						"Fletched/Hr:  "
								+ ((int) (new Double(strung)
										/ new Double(System.currentTimeMillis()
												- startTime) * new Double(
										60 * 60 * 1000))), 60, 444);
			}
			g2.drawString("Status:  " + status, 60, 466);
		} else if (!fullPaint && isClicking && game.isLoggedIn()) {
			g2.drawImage(show, 9, 347, null);
			g2.drawImage(watermark, 305, 315, null);
		} else if (fullPaint && isClicking) {
			g2.setColor(TAN2);
			g2.fillRect(6, 344, 507, 129);
			g2.drawImage(paint, 6, 344, null);
			g2.drawImage(hide, 9, 347, null);
			g2.drawImage(guiButton, 360, 440, null);
			g2.drawImage(watermark, 305, 315, null);
			g2.setFont(new Font("Arial", 1, 15));
			g2.setColor(GREENISH2);
			g2.drawString("Time Running: " + getRuntime(), 60, 372);
			g2.drawString(
					"Exp Gained: "
							+ (skills.getCurrentExp(Skills.FLETCHING) - startXP),
					60, 391);
			g2.drawString(
					"Exp/H: "
							+ getHourly(skills.getCurrentExp(Skills.FLETCHING)
									- startXP), 60, 409);
			g2.drawString("Fletched/Strung:  " + fletched, 60, 426);
			g2.drawString(
					"Fletched/Hr:  "
							+ ((int) (new Double(fletched)
									/ new Double(System.currentTimeMillis()
											- startTime) * new Double(
									60 * 60 * 1000))), 60, 444);
			g2.drawString("Status:  " + status, 60, 466);
		} else {
			g2.drawImage(show, 9, 347, null);
			g2.drawImage(watermark, 305, 315, null);
		}

		if (game.isLoggedIn() && !isClicking && fullPaint) {
			// =========> PROGRESS <=========
			double percent = skills.getPercentToNextLevel(Skills.FLETCHING) * 5.2;
			GradientPaint red = new GradientPaint(4, 3, new Color(181, 55, 55,
					255), 4, 25, new Color(207, 104, 103, 255));
			GradientPaint green = new GradientPaint(4, 3, new Color(90, 168,
					51, 255), 4, 25, new Color(134, 205, 99, 255));
			g2.setPaint(red);
			g2.fillRect(4, 3, 512, 22);
			g2.setPaint(green);
			g2.fillRect(4, 3, (int) percent, 22);
			g2.setColor(Color.black);
			g2.drawRect(4, 3, 512, 22);
			g2.setFont(new Font("Arial", 0, 13));
			String progress = skills.getPercentToNextLevel(Skills.FLETCHING)
					+ "% to " + (skills.getCurrentLevel(Skills.FLETCHING) + 1)
					+ " Fletching | "
					+ skills.getExpToNextLevel(Skills.FLETCHING)
					+ "XP Until level | " + hoursTNL + " Hours, " + minsTNL
					+ " Mins Until level";
			g2.setColor(BLACK);
			g2.drawString(progress, 12, 19);

		} else if (game.isLoggedIn() && isClicking && fullPaint) {

			double percent = skills.getPercentToNextLevel(Skills.FLETCHING) * 5.2;
			GradientPaint red = new GradientPaint(4, 3, new Color(181, 55, 55,
					100), 4, 25, new Color(207, 104, 103, 100));
			GradientPaint green = new GradientPaint(4, 3, new Color(90, 168,
					51, 100), 4, 25, new Color(134, 205, 99, 100));
			g2.setPaint(red);
			g2.fillRect(4, 3, 512, 22);
			g2.setPaint(green);
			g2.fillRect(4, 3, (int) percent, 22);
			g2.setColor(Color.black);
			g2.drawRect(4, 3, 512, 22);
			g2.setFont(new Font("Arial", 0, 13));
			String progress = skills.getPercentToNextLevel(Skills.FLETCHING)
					+ "% to " + (skills.getCurrentLevel(Skills.FLETCHING) + 1)
					+ " Fletching | "
					+ skills.getExpToNextLevel(Skills.FLETCHING)
					+ "XP Until level | " + hoursTNL + " Hours, " + minsTNL
					+ " Mins Until level";
			g2.setColor(BLACK);
			g2.drawString(progress, 12, 19);
		}

		// ==========> MOUSE! <==========
		Point m = mouse.getLocation();
		g2.setColor(RED);
		g2.fillRect(m.x - 5, m.y, 12, 2);
		g2.fillRect(m.x, m.y - 5, 2, 12);
		if (gui.checkBox3.isSelected()) {
			while (!mousePath.isEmpty() && mousePath.peek().isUp())
				mousePath.remove();
			Point clientCursor = mouse.getLocation();
			MousePathPoint mpp = new MousePathPoint(clientCursor.x,
					clientCursor.y, 3000);
			if (mousePath.isEmpty() || !mousePath.getLast().equals(mpp))
				mousePath.add(mpp);
			MousePathPoint lastPoint = null;
			for (MousePathPoint a : mousePath) {
				if (lastPoint != null) {
					g2.setColor(a.getColor());
					g2.drawLine(a.x, a.y, lastPoint.x, lastPoint.y);
				}
				lastPoint = a;
			}
		}

		if (gui.checkBox3.isSelected()) {
			while (!mousePath2.isEmpty() && mousePath2.peek().isUp2())
				mousePath2.remove();
			MousePathPoint2 mpp = new MousePathPoint2(z.x, z.y, 3000);
			if (mousePath2.isEmpty() || !mousePath2.getLast().equals(mpp))
				mousePath2.add(mpp);
			MousePathPoint2 lastPoint = null;
			for (MousePathPoint2 z : mousePath2) {
				if (lastPoint != null) {
					g2.setColor(z.getColor2());
					g2.drawLine(z.x, z.y, lastPoint.x, lastPoint.y);
				}
				lastPoint = z;
			}
		}
		if (gui.checkBox4.isSelected()) {
			int gW = game.getWidth();
			int gH = game.getHeight();
			Point localPoint = mouse.getLocation();
			g2.setColor(new Color(0, 250, 0));
			g2.drawLine(0, localPoint.y, gW, localPoint.y);
			g2.drawLine(localPoint.x, 0, localPoint.x, gH);
		}
		if (gui.checkBox4.isSelected()) {
			int gW = game.getWidth();
			int gH = game.getHeight();
			g2.setColor(new Color(255, 0, 0));
			g2.drawLine(0, z.y, gW, z.y);
			g2.drawLine(z.x, 0, z.x, gH);
		}
	}

	private int getHourly(final int input) {
		double millis = System.currentTimeMillis() - startTime;
		return (int) ((input / millis) * 3600000);
	}

	public String getRuntime() {
		try {
			long millis = System.currentTimeMillis() - startTime;
			long hours = millis / (1000 * 60 * 60);
			millis -= hours * (1000 * 60 * 60);
			long minutes = millis / (1000 * 60);
			millis -= minutes * (1000 * 60);
			long seconds = millis / 1000;
			return ("" + (hours < 10 ? "0" : "") + hours + ":"
					+ (minutes < 10 ? "0" : "") + minutes + ":"
					+ (seconds < 10 ? "0" : "") + seconds + "");
		} catch (Exception e) {
			return "";
		}
	}

	public int getValue(boolean b) {
		if (b)
			return 1;
		return 0;
	}

	public void loadSettings() {
		if (!new File("UFletch.ini").exists()) {
			return;
		}
		try {
			DataInputStream in = new DataInputStream(new FileInputStream(
					"UFletch.ini"));
			BufferedReader br = new BufferedReader(new InputStreamReader(in));
			String line;
			while ((line = br.readLine()) != null) {
				try {
					boolean checkWhat = false;
					int w = -1;
					String isDoing = "";
					for (char c : line.toCharArray()) {
						if (c == '<' || checkWhat) {
							if (c == '<') {
								isDoing = "";
							}
							checkWhat = true;
							isDoing += c;
							if (c == '>') {
								if (isDoing.contains("<Method>")) {
									w = 1;
								} else if (isDoing.contains("<LogType>")) {
									w = 2;
								} else if (isDoing.contains("<BowType>")) {
									w = 3;
								} else if (isDoing.contains("<KnifeType>")) {
									w = 4;
								} else if (isDoing.contains("<Amount>")) {
									w = 5;
								} else if (isDoing.contains("<Name>")) {
									w = 6;
								} else if (isDoing.contains("<MouseLines>")) {
									w = 7;
								} else if (isDoing.contains("<MouseCross>")) {
									w = 8;
								} else if (isDoing.contains("<WhenDone>")) {
									w = 9;
								} else if (isDoing.contains("<UponLevel>")) {
									w = 10;
								} else if (isDoing.contains("<Before99>")) {
									w = 11;
								} else if (isDoing.contains("<Save>")) {
									w = 12;
								} else if (isDoing.contains("<Speed>")) {
									w = 13;
								}
								checkWhat = false;
								isDoing = "";
							}
							continue;
						} else if (w == 1 || w == 2 || w == 3 || w == 4
								|| w == 6) {
							if (c == '(') {
								isDoing = "";
							} else if (c == ',' || c == ')') {
								if (w == 1) {
									gui.comboBox1.setSelectedItem(isDoing);
								} else if (w == 2) {
									gui.comboBox2.setSelectedItem(isDoing);
								} else if (w == 3) {
									gui.comboBox3.setSelectedItem(isDoing);
								} else if (w == 4) {
									gui.comboBox4.setSelectedItem(isDoing);
								} else if (w == 6) {
									gui.textField2.setText(isDoing);
								}
							} else {
								isDoing += c;
							}
						} else {
							if (c == '(') {
								isDoing = "";
							} else if (c == ',' || c == ')') {
								int tempID = Integer.parseInt(isDoing);
								boolean val = false;
								if (tempID == 1) {
									val = true;
								}
								if (w == 5) {
									gui.textField1.setText(isDoing);
								} else if (w == 7) {
									gui.checkBox3.setSelected(val);
								} else if (w == 8) {
									gui.checkBox4.setSelected(val);
								} else if (w == 9) {
									gui.checkBox1.setSelected(val);
								} else if (w == 10) {
									gui.checkBox2.setSelected(val);
								} else if (w == 11) {
									gui.checkBox5.setSelected(val);
								} else if (w == 12) {
									gui.checkBox6.setSelected(val);
								} else if (w == 13) {
									gui.slider1.setValue(tempID);
								}
								isDoing = "";
							} else if (c == '0' || c == '1' || c == '2'
									|| c == '3' || c == '4' || c == '5'
									|| c == '6' || c == '7' || c == '8'
									|| c == '9') {
								isDoing += c;
							}
						}
					}
				} catch (Exception e) {
				}
			}
			in.close();
		} catch (Exception e) {
			return;
		}
	}

	public void saveSettings() {
		try {
			ArrayList<String> s = new ArrayList<String>();
			s.add("<Method>(" + (String) gui.comboBox1.getSelectedItem() + ")");
			s.add("<LogType>(" + (String) gui.comboBox2.getSelectedItem() + ")");
			s.add("<BowType>(" + (String) gui.comboBox3.getSelectedItem() + ")");
			s.add("<KnifeType>(" + (String) gui.comboBox4.getSelectedItem()
					+ ")");
			s.add("<Amount>(" + (String) gui.textField1.getText() + ")");
			s.add("<Name>(" + (String) gui.textField2.getText() + ")");
			s.add("<MouseLines>(" + getValue(gui.checkBox3.isSelected()) + ")");
			s.add("<MouseCross>(" + getValue(gui.checkBox4.isSelected()) + ")");
			s.add("<WhenDone>(" + getValue(gui.checkBox1.isSelected()) + ")");
			s.add("<UponLvl>(" + getValue(gui.checkBox2.isSelected()) + ")");
			s.add("<Before99>(" + getValue(gui.checkBox5.isSelected()) + ")");
			s.add("<Save>(" + getValue(gui.checkBox6.isSelected()) + ")");
			s.add("<Speed>(" + (int) gui.slider1.getValue() + ")");

			final BufferedWriter writer = new BufferedWriter(new FileWriter(
					"UFletch.ini"));
			for (String str : s) {
				writer.write(str);
				writer.newLine();
			}
			writer.close();
		} catch (Exception e) {

		}
	}

	public class gui extends JFrame {

		private static final long serialVersionUID = 1L;

		public gui() {
			initComponents();
		}

		private void button1ActionPerformed(ActionEvent e) {
			setVisible(false);
			if (checkBox6.isSelected()) {
				saveSettings();
			}
			log("Task: " + optionLog[gui.comboBox2.getSelectedIndex()] + " "
					+ optionBow[gui.comboBox3.getSelectedIndex()] + " "
					+ optionMethod[gui.comboBox1.getSelectedIndex()]);
			Mouse1 = (int) slider1.getValue();
			if (Mouse1 == 100) {
				Mouse2 = random(1, 2);
			} else if (Mouse1 == 90) {
				Mouse2 = random(2, 4);
			} else if (Mouse1 == 80) {
				Mouse2 = random(3, 5);
			} else if (Mouse1 == 70) {
				Mouse2 = random(4, 6);
			} else if (Mouse1 == 60) {
				Mouse2 = random(5, 7);
			} else if (Mouse1 == 50) {
				Mouse2 = random(6, 8);
			} else if (Mouse1 == 40) {
				Mouse2 = random(7, 9);
			} else if (Mouse1 == 30) {
				Mouse2 = random(8, 10);
			} else if (Mouse1 == 20) {
				Mouse2 = random(10, 12);
			} else if (Mouse1 == 10) {
				Mouse2 = random(12, 14);
			}
			mouse.setSpeed(Mouse2);
			button4.setEnabled(false);
			button3.setEnabled(false);
			button2.setEnabled(false);
			textField2.setEnabled(false);
		}

		private void button2ActionPerformed(ActionEvent e) {
			checkForUpdates();
		}

		private void button4ActionPerformed(ActionEvent e) {
			try {
				new URL(
						"http://www.universalscripts.org/UFletch_submit.php?auth="
								+ gui.textField2.getText()).openStream();
				button4.setEnabled(false);
			} catch (MalformedURLException e1) {
				log(e.toString());
			} catch (IOException e1) {
				log(e.toString());
			}
		}

		private void button5ActionPerformed(ActionEvent e) {
			try {
				Desktop.getDesktop()
						.browse(new URL(
								"https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=WCYVXS8Z7X63C")
								.toURI());
			} catch (MalformedURLException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			} catch (URISyntaxException e1) {
				e1.printStackTrace();
			}
		}

		private void button3ActionPerformed(ActionEvent e) {
			try {
				Desktop.getDesktop().browse(
						new URL(
								"http://www.universalscripts.org/UFletch_generate.php?user="
										+ gui.textField2.getText()).toURI());
			} catch (MalformedURLException e1) {
				e1.printStackTrace();
			} catch (IOException e1) {
				e1.printStackTrace();
			} catch (URISyntaxException e1) {
				e1.printStackTrace();
			}
		}

		private void initComponents() {
			// JFormDesigner - Component initialization - DO NOT MODIFY
			// //GEN-BEGIN:initComponents
			slider1 = new JSlider();
			button1 = new JButton();
			label1 = new JLabel();
			label2 = new JLabel();
			label3 = new JLabel();
			label4 = new JLabel();
			label5 = new JLabel();
			label7 = new JLabel();
			label8 = new JLabel();
			checkBox1 = new JCheckBox();
			checkBox2 = new JCheckBox();
			label9 = new JLabel();
			checkBox3 = new JCheckBox();
			checkBox4 = new JCheckBox();
			label10 = new JLabel();
			textField1 = new JTextField();
			label11 = new JLabel();
			label12 = new JLabel();
			label13 = new JLabel();
			label14 = new JLabel();
			label15 = new JLabel();
			comboBox1 = new JComboBox(optionMethod);
			comboBox2 = new JComboBox(optionLog);
			comboBox3 = new JComboBox(optionBow);
			comboBox4 = new JComboBox(optionKnife);
			label16 = new JLabel();
			checkBox5 = new JCheckBox();
			label17 = new JLabel();
			textField2 = new JTextField();
			label18 = new JLabel();
			button2 = new JButton();
			button4 = new JButton();
			button5 = new JButton();
			button3 = new JButton();
			checkBox6 = new JCheckBox();
			label6 = new JLabel();
			label19 = new JLabel();
			label20 = new JLabel();
			label21 = new JLabel();
			label22 = new JLabel();

			// ======== frame1 ========
			{
				Container ContentPane = getContentPane();
				ContentPane.setLayout(null);

				// ---- slider1 ----
				slider1.setSnapToTicks(true);
				slider1.setPaintTicks(true);
				slider1.setMajorTickSpacing(10);
				ContentPane.add(slider1);
				slider1.setBounds(95, 230, slider1.getPreferredSize().width, 30);

				// ---- button1 ----
				button1.setText("START");
				button1.setForeground(Color.blue);
				button1.setFont(new Font("Tahoma", Font.PLAIN, 57));
				button1.setBackground(Color.blue);
				ContentPane.add(button1);
				button1.setBounds(5, 385, 300, 75);
				button1.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						button1ActionPerformed(e);
					}
				});

				// ---- label1 ----
				label1.setText("Mousespeed:");
				ContentPane.add(label1);
				label1.setBounds(15, 230, 75, 30);

				// ---- label2 ----
				label2.setText("UFletch - AIO");
				label2.setFont(label2.getFont().deriveFont(
						label2.getFont().getSize() + 17f));
				label2.setForeground(Color.blue);
				ContentPane.add(label2);
				label2.setBounds(10, 0, 185, 35);

				// ---- label3 ----
				label3.setText("Developed By");
				label3.setForeground(Color.red);
				label3.setFont(new Font("Tahoma", Font.PLAIN, 20));
				ContentPane.add(label3);
				label3.setBounds(185, -15, 130, 60);

				// ---- label4 ----
				label4.setText("_______________");
				label4.setFont(label4.getFont().deriveFont(
						label4.getFont().getSize() + 4f));
				label4.setForeground(Color.red);
				ContentPane.add(label4);
				label4.setBounds(185, 10, 125, 15);

				// ---- label5 ----
				label5.setText("Fletch To 99");
				label5.setForeground(Color.magenta);
				label5.setFont(label5.getFont().deriveFont(
						label5.getFont().getSize() + 12f));
				ContentPane.add(label5);
				label5.setBounds(180, 30, 130, label5.getPreferredSize().height);

				// ---- label7 ----
				label7.setText("FREE");
				label7.setFont(label7.getFont().deriveFont(
						label7.getFont().getSize() + 17f));
				label7.setForeground(Color.blue);
				ContentPane.add(label7);
				label7.setBounds(new Rectangle(new Point(65, 35), label7
						.getPreferredSize()));

				// ---- label8 ----
				label8.setText("Save Screenshot when done:");
				ContentPane.add(label8);
				label8.setBounds(15, 180, label8.getPreferredSize().width, 24);

				// ---- checkBox1 ----
				checkBox1.setText(" Upon Level:");
				checkBox1.setSelected(true);
				ContentPane.add(checkBox1);
				checkBox1.setBounds(new Rectangle(new Point(165, 180),
						checkBox1.getPreferredSize()));

				// ---- checkBox2 ----
				checkBox2.setSelected(true);
				ContentPane.add(checkBox2);
				checkBox2.setBounds(new Rectangle(new Point(250, 180),
						checkBox2.getPreferredSize()));

				// ---- label9 ----
				label9.setText("Draw mouse lines:");
				ContentPane.add(label9);
				label9.setBounds(15, 160, label9.getPreferredSize().width, 25);

				// ---- checkBox3 ----
				checkBox3.setText("  Draw mouse crosshair:");
				checkBox3.setSelected(true);
				ContentPane.add(checkBox3);
				checkBox3.setBounds(new Rectangle(new Point(105, 160),
						checkBox3.getPreferredSize()));

				// ---- checkBox4 ----
				checkBox4.setSelected(true);
				ContentPane.add(checkBox4);
				checkBox4.setBounds(245, 160, 25, 21);

				// ---- label10 ----
				label10.setText("Amount to Fletch:");
				ContentPane.add(label10);
				label10.setBounds(15, 140, 90, 19);

				// ---- textField1 ----
				textField1.setText("0");
				ContentPane.add(textField1);
				textField1.setBounds(110, 140, 60,
						textField1.getPreferredSize().height);

				// ---- label11 ----
				label11.setText("0 for Unilimted Fletching!");
				ContentPane.add(label11);
				label11.setBounds(180, 140, label11.getPreferredSize().width,
						20);

				// ---- label12 ----
				label12.setText("Method:");
				ContentPane.add(label12);
				label12.setBounds(15, 75, label12.getPreferredSize().width, 20);

				// ---- label13 ----
				label13.setText("Log Type:");
				ContentPane.add(label13);
				label13.setBounds(15, 110, label13.getPreferredSize().width, 20);

				// ---- label14 ----
				label14.setText("Bow Type:");
				ContentPane.add(label14);
				label14.setBounds(190, 75, label14.getPreferredSize().width, 20);

				// ---- label15 ----
				label15.setText("Knife Type:");
				ContentPane.add(label15);
				label15.setBounds(190, 105, label15.getPreferredSize().width,
						20);
				ContentPane.add(comboBox1);
				comboBox1.setBounds(65, 75, 110,
						comboBox1.getPreferredSize().height);
				ContentPane.add(comboBox2);
				comboBox2.setBounds(75, 110, 100,
						comboBox2.getPreferredSize().height);
				ContentPane.add(comboBox3);
				comboBox3.setBounds(250, 75, 55,
						comboBox3.getPreferredSize().height);
				ContentPane.add(comboBox4);
				comboBox4.setBounds(250, 105, 55,
						comboBox4.getPreferredSize().height);

				// ---- label16 ----
				label16.setText("logout 20k exp before 99 fletching:");
				ContentPane.add(label16);
				label16.setBounds(15, 205, 180, 20);

				// ---- checkBox5 ----
				checkBox5.setSelected(true);
				ContentPane.add(checkBox5);
				checkBox5.setBounds(new Rectangle(new Point(190, 205),
						checkBox5.getPreferredSize()));

				// ---- label17 ----
				label17.setText("Signature name:");
				ContentPane.add(label17);
				label17.setBounds(15, 265, 80, 19);

				// ---- textField2 ----
				textField2.setText("all");
				ContentPane.add(textField2);
				textField2.setBounds(100, 265, 95,
						textField2.getPreferredSize().height);

				// ---- label18 ----
				label18.setText("Leave blank for none");
				ContentPane.add(label18);
				label18.setBounds(200, 265, label18.getPreferredSize().width,
						20);

				// ---- button2 ----
				button2.setText("Check For Updates");
				button2.setForeground(Color.red);
				button2.setBackground(Color.red);
				ContentPane.add(button2);
				button2.setBounds(160, 325, 145, 35);
				button2.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						button2ActionPerformed(e);
					}
				});

				// ---- button4 ----
				button4.setText("Generate Signature");
				button4.setForeground(new Color(0, 204, 0));
				button4.setBackground(new Color(0, 204, 0));
				ContentPane.add(button4);
				button4.setBounds(5, 290, 155, 35);
				button4.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						button4ActionPerformed(e);
					}
				});

				// ---- button5 ----
				button5.setText("Donate");
				button5.setForeground(Color.red);
				button5.setBackground(Color.red);
				ContentPane.add(button5);
				button5.setBounds(5, 325, 155, 35);
				button5.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						button5ActionPerformed(e);
					}
				});

				// ---- button3 ----
				button3.setText("View Signature");
				button3.setBackground(new Color(0, 204, 51));
				button3.setForeground(new Color(0, 204, 0));
				ContentPane.add(button3);
				button3.setBounds(160, 290, 145, 35);
				button3.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent e) {
						button3ActionPerformed(e);
					}
				});

				// ---- checkBox6 ----
				checkBox6.setSelected(true);
				ContentPane.add(checkBox6);
				checkBox6.setBounds(new Rectangle(new Point(80, 360), checkBox6
						.getPreferredSize()));

				// ---- label6 ----
				label6.setText("Save Settings:");
				ContentPane.add(label6);
				label6.setBounds(10, 360, 70, 20);

				// ---- label19 ----
				label19.setText("Latest Ver:");
				ContentPane.add(label19);
				label19.setBounds(105, 360, 60, 20);

				// ---- label20 ----
				label20.setText(newversion());
				ContentPane.add(label20);
				label20.setBounds(165, 360, 40, 20);

				// ---- label21 ----
				label21.setText("Your Ver:");
				ContentPane.add(label21);
				label21.setBounds(215, 360, 50, 20);

				// ---- label22 ----
				label22.setText(urversion());
				ContentPane.add(label22);
				label22.setBounds(275, 360, label22.getPreferredSize().width,
						20);

				ContentPane.setPreferredSize(new Dimension(315, 480));
				pack();
				setLocationRelativeTo(getOwner());
			}
			// JFormDesigner - End of component initialization
			// //GEN-END:initComponents
		}

		// JFormDesigner - Variables declaration - DO NOT MODIFY
		// //GEN-BEGIN:variables
		private JSlider slider1;
		private JButton button1;
		private JLabel label1;
		private JLabel label2;
		private JLabel label3;
		private JLabel label4;
		private JLabel label5;
		private JLabel label7;
		private JLabel label8;
		private JCheckBox checkBox1;
		private JCheckBox checkBox2;
		private JLabel label9;
		private JCheckBox checkBox3;
		private JCheckBox checkBox4;
		private JLabel label10;
		private JTextField textField1;
		private JLabel label11;
		private JLabel label12;
		private JLabel label13;
		private JLabel label14;
		private JLabel label15;
		private JComboBox comboBox1;
		private JComboBox comboBox2;
		private JComboBox comboBox3;
		private JComboBox comboBox4;
		private JLabel label16;
		private JCheckBox checkBox5;
		private JLabel label17;
		private JTextField textField2;
		private JLabel label18;
		private JButton button2;
		private JButton button4;
		private JButton button5;
		private JButton button3;
		private JCheckBox checkBox6;
		private JLabel label6;
		private JLabel label19;
		private JLabel label20;
		private JLabel label21;
		private JLabel label22;
		// JFormDesigner - End of variables declaration //GEN-END:variables
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		p = e.getPoint();
		if (p.x >= 9 && p.x <= 36 && p.y >= 347 && p.y <= 372) {
			if (fullPaint) {
				fullPaint = false;
			} else if (!fullPaint) {
				fullPaint = true;
			}
		}

		if (p.x >= 360 && p.x <= 460 && p.y >= 440 && p.y <= 464) {
			gui.button1.setText("Update!");
			gui.setVisible(true);
		}
	}

	public void mouseEntered(MouseEvent e) {
	}

	public void mouseExited(MouseEvent e) {
	}

	public void mousePressed(MouseEvent e) {
		p2 = e.getPoint();
		if (p2.x >= 4 && p2.x <= 514 && p2.y >= 345 && p2.y <= 473) {
			isClicking = true;
		}
	}

	public void mouseReleased(MouseEvent e) {
		p2 = e.getPoint();
		if (p2.x >= 4 && p2.x <= 514 && p2.y >= 345 && p2.y <= 473) {
			isClicking = false;
		}
	}

	public void mouseDragged(MouseEvent e) {
	}

	public void mouseMoved(MouseEvent e) {
		z = e.getPoint();
	}

}